<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">



	<title>Swap Sentence</title>
<script charset="utf-8" id="injection_graph_func" src="js/injection_graph_func.js"></script></head><body>
<script>
/*
var test = "1,2,3,4,5,6,7,8,9,10"
for (i=0; i<1959552; i++){
	swapSentence(test);
}
*/
function swapSentence(){
	var temp = swapArray(document.getElementById("src").value);
	document.getElementById("res").value = temp;
}


function swapArray(source){
	var arSc= source.split(".");
	var i, len;
	var arRet = Array();
	len = arSc.length;
	for (i=0; i<len; i++){
		var temp = RandBetween(i,len -1);
		//document.write("i=" + i +  " ; len=" + len + " ; temp = " + temp + "<br>" )
		swap(arSc, i, temp);
	}
	//document.write(arSc.join(",") + "<br><br>");
	return arSc.join(".");
}
function swap(arr, x, y){
	var temp = arr[x];
	arr[x]=arr[y];
	arr[y]=temp;
}


function randNumber(number){
	return Math.round(Math.random() * number)
}
// returns a random integer between low and high inclusive 
function RandBetween(low, high){ 
	if (high == low) {return low; }
	else {
		var t;
		do {t = randNumber(high);}
		while(t == low || t < low)
		return t;
	}
}
</script>

<table>
	<tbody><tr>
		<td valign="top">Source</td>
		<td><textarea cols="" rows="15" name="source" id="src" style="width: 500px;"></textarea></td>
	</tr>
	<tr>
		<td valign="top">Result</td>
		<td><textarea cols="" rows="15" name="result" id="res" style="width: 500px;"></textarea></td>
	</tr>	
	<tr><td>&nbsp;</td><td><input value="Random" onclick="swapSentence();" type="button"></td></tr>
</tbody></table>
</body></html>